<template>
  <div class="login-container">
    <div class="logo" />
    <div class="form">
      <p class="title">智慧园区-登录</p>
      <el-card shadow="never" class="login-card">
        <!--登录表单-->
        <el-form ref="form" :model="form" :rules="loginRules" :label-position="laberposition">
          <el-form-item prop="username" label="账号">
            <el-input v-model="form.username" placeholder="请输入账号" />
          </el-form-item>
          <el-form-item prop="password" label="密码">
            <el-input v-model="form.password" show-password placeholder="请输入密码" />
          </el-form-item>
          <el-form-item prop="id" label="模型uuid">
            <el-input v-model="form.id" show-password placeholder="请输入模型uuid" />
          </el-form-item>
          <el-form-item>
            <el-checkbox>记住我</el-checkbox>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" style="width: 300px;" @click="submit">登录</el-button>
          </el-form-item>
        </el-form>
      </el-card>
    </div>
  </div>

</template>

<script>

export default {
  name: 'Login',
  data() {
    return {
      laberposition: 'top',
      form: {
        username: process.env.NODE_ENV === 'development' ? 'demo' : '',
        password: process.env.NODE_ENV === 'development' ? 'Hmzs%001' : '',
        id: process.env.NODE_ENV === 'development' ? '66ea8d2a-7416-4be5-ba7e-c030cf88b3f3' : ''
        // isAgree: process.env.NODE_ENV === 'development'
      },
      loginRules: {
        username: [{ required: true, message: '请输入账号', trigger: ['blur'] }],
        password: [{ required: true, message: '请输入密码', trigger: ['blur'] }],
        id: [{ required: true, message: '请输入任意生成的模型id!', trigger: ['blur'] }]
        // isAgree: [{
        //   validator: (rule, value, callback) => {
        //     value ? callback() : callback(new Error('没有勾选用户平台协议'))
        //   }
        // }]
      }
    }
  },
  watch: {

  },
  methods: {
    submit() {
      this.$refs.form.validate(async valid => {
        if (!valid) {
          return
        }
        const { username, password } = this.form
        this.$store.dispatch('user/login', { username, password })
      })
    }
  }
}
</script>

<style lang="scss">
span {
  display:block;
}

.login-container {
  height: 100vh;
  display: flex;
  align-items: stretch;

  .logo {
    flex: 3;
    background-image: url('../../assets/404_images/start.jpg');
    background-repeat: no-repeat;
    background-size: cover;
    background-position: center;
    border-top-right-radius: 60px;
  }

  .form {
    width: 100vh;
    flex: 1.5;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding-left: 130px;
    padding-right: 70px;

    .login-card {
      border: none;
      padding: 0;

    }

    .el-input {
      width: 300px;
      height: 44px;
    }

    .title {
      padding-left: 20px;
      font-size: 24px;
    }

  }
}
</style>
